package puzzle.projecteuler.p200;

public class Problem135B {

	/**
	 * 	 (a+2*d)^2 - (a+d)^2 - a^2
	 * = - a^2 + 2ad + 3d^2
	 * = (3d-a)(a+d) = n
	 * 
	 * => n = s*t, 3d-a=s, a+d=t
	 * 
	 * => a = (3t - s)/4
	 *    d = ( s + t)/4
	 *    n = s*t
	 *    NOTE: 3t>s => 3st>s^2 => s < sqrt(3*n)
	 *    
	 * 程序还有点慢, :(。大概1、2分钟。
	 * @param args
	 */
	public static void main(String[] args) {

		int c = 0;
		for (int n = 1155; n < 1000000; n ++) {
			if (count(n) == 10) {
				c ++;
			}
		}
		System.out.println(c);
	}
	
	public static int count(int n) {
		int c = 0;
		for (int s = 1; s < (int)Math.sqrt(3*n); s ++) {
			if (n%s == 0) {
				int t = n/s;
				if ((s+t)%4 == 0) {
					c ++;
				}
			}
		}
		return c;
	}

}
